<script type="text/javascript"
        src="${baseStaticUrl}/plugins/bootstrap-table/bootstraptable-treeview.js"></script>
<div class="box">
	<div class="box-body">
		<div class="row marginZero">
			<div class="table-responsive">
				<div id="sysDeptTable_toolbar" class="row visa-row">
					<div class="col-md-12">
						<div class="globalbtn">
							<button id="add_method" type="button" class="btn btn-primary btn-sm" onclick="addClick()">
						        <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
						    </button>
						    <button id="delete_method" type="button" class="btn btn-danger btn-sm">
						        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
						    </button>
						</div>
					</div>
				</div>
				<div id="sysDeptTable"></div>
	        </div>
		</div>
	</div>
</div>
<script type="text/javascript">
	var columns=[
		{
            radio:true
        },
	    {title: '组织名称', field: 'org_name',width:"25%",
        	formatter: function(value,item, index){
                return "<a href='javascript:void(0)' onclick=\"viewAddPage('"+item.id+"')\">"+value+"</a>";
            }
        },
	    {title: '组织编码', field: 'org_code',width:"15%"},
	    {title: '上级组织', field: 'parent_name',width:"15%"},
	    {title: '类型', field: 'org_type',width:"10%" },
	    {title: '组织简称', field: 'short_name',width:"15%"},
	    {title: '状态', field: 'status',width:"10%"},
	    {title: '操作', field: 'operation',width:"10%",
	    	formatter: function(value,item, index){
                return "<button class='btn btn-danger btn-xs' onclick=\"delRows('"+item.id+"')\">"+
                "<span class='glyphicon glyphicon-remove' aria-hidden='true'></span>删除";
            }
	    }
    ];
    $('#sysDeptTable').bootstrapTable({
    	classes: "table table-hover table-striped",
        url:'${basePath}/sys/org/findOrgListAjax',
        sidePagination: 'server',
        toolbar: "#sysDeptTable_toolbar",
        pagination: false,
        treeView: true,
        treeId: "id",
        cache: false,
        showRefresh:true,
        treeField: "org_name",
        columns: columns,
        ajax: function ajaxRequest(request) {
        	$.ajax({
                type:request.type,
                url:request.url,
                timeout:0,
                data:request.data,
                cache:request.cache,
                success:function(result,status,xhr){
                    var obj = {};
                    obj.total = result.totalRow;
                    obj.rows = result.list;
                    request.success(obj);
                },
                error:function(xhr,status,err){
                    console.warn("ajax response error: {status:'" + status + "',exception:'" + err + "'}");
                    request.error({status:status,resp:xhr});
                }
            });
	    }
    });
    
    function viewAddPage(id){
    	if(id!=null){
	        _tabs.showPage("information",null,'ID=' + id,null);
	    }else {
	        _tabs.showPage("information",null,null,null);
	    }
    }
    
    function delRows(id){
    	CommonUtil.del(null,id,"${basePath}/sys/dept/delete",null,function(){
            _tabs.showPage("list");
        });
    }
    
    function clickDelete(){
    	var selRows = $("#sysDeptTable").bootstrapTable("getSelections");
    	CommonUtil.del(selRows,"id","${basePath}/sys/dept/delete",null,function(){
            _tabs.showPage("list");
        });
    }
    
    function addClick(){
    	_tabs.showPage("information",null,null,null);
    }
</script>